package com.xjh.basestudy.javabase.io.characterio;


import java.io.*;

public class myCharStream {
    public static void main(String[] args) throws IOException {
        //使用默认字符编码写数据
//        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("javabase\\osw.txt"));
        //指定字符编码写数据
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("javabase\\osw.txt"),"gbk");
        osw.write("中国");
        osw.close();
        //读数据
        InputStreamReader isr = new InputStreamReader(new FileInputStream("javabase\\osw.txt"),"gbk");
        //一次读一个字符数据
        int ch;
        while((ch=isr.read())!=-1){
            System.out.println((char)ch);
        }
        isr.close();

    }
}
